<template>
  <div class="topbar">
    <div class="topbar-logo">
      <img src="../assets/images/logo.1296c0b5.jpg" class="img" alt="" />
      <el-main>
                      <el-breadcrumb
          separator="/"
          v-if="$router.path !== '/homepage'"
        >
                          <el-breadcrumb-item
            :to="{ path: '/homepage' }"
            class="iconfont icon-shouye-shouye"
            >首页</el-breadcrumb-item
          >  
        </el-breadcrumb>
      </el-main>
      <span class="user">{{ username }}，周末的晚霞，别有一番风景</span>
    </div>
    <div class="topbar-login">
                  <el-dropdown trigger="click">
                      <span style="padding-right: 70px">
                          <i
            class="iconfont icon-shezhi"
            style="padding-left: 20px"
          ></i
          >设置               </span
        >
                      <el-dropdown-menu slot="dropdown">
                          <el-dropdown-item
            v-for="(item, index) in rightNav"
            :key="index"
            style="width: 130px"
            :icon="item.icon"
          >
                              <router-link
              :to="item.path"
              style="color: black"
              >{{ item.text }}</router-link
            >
                            </el-dropdown-item
          >
                        </el-dropdown-menu
        >
                    </el-dropdown
      >
      <el-button @click="btn" class="btn" type="danger" round>退出</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username:localStorage.getItem('admin'),
      rightNav: [
        {
          path: "/building",
          text: "楼栋管理",
          icon: "iconfont icon-loudong",
        },
        {
          path: "/houses",
          text: "房间管理",
          icon: "iconfont icon-fangjianguanli",
        },
        {
          path: "/administrator",
          text: "管理员管理",
          icon: "iconfont icon-guanliyuan",
        },
        {
          path: "/administratorrole",
          text: "角色管理",
          icon: "iconfont icon-jiaoseguanli",
        },
      ],
    };
  },
  mounted() {
    this.onName();
  },
  methods: {
    homepage() {
      this.$touter.push("/homepage");
    },
    logout() {
      sessionStorage.clear();
      this.$router.push("/login");
    },

    onName() {
      this.username = sessionStorage.getItem("username");
    },
    btn() {
      this.$confirm("是否退出登录?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        sessionStorage.clear();
        this.$router.push("/Login");
        this.$confirm("确定要退出吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.$message({
              type: "success",
              message: "退出成功!",
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消退出",
            });
          });
      });
    },
  },
};
</script>

<style lang="less" scoped>
.el-header {
  width: 100%;
  padding: 0;
  background-color: #f4f4f4;
}
.img {
  width: 200px !important;
  height: 60px;
}
.logout {
  text-align: right;
  margin-top: -60px;
  display: flex;
  margin-left: 200px;
}
.topbar {
  display: flex;
  justify-content: space-between;
}
.topbar-logo {
  display: flex;
  line-height: 80px;
}
.out {
  margin-top: 20px;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
  margin-top: -300px;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.el-dropdown-link {
  margin-right: 40px;
  color: black;
}
.tony {
  margin-top: 30px;
}
</style>